<?php
namespace Modules\Admin\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Modules\Admin\Entities\Chatgroup;
use Modules\Admin\Entities\Manage;
use Modules\Admin\Entities\Role;
use Modules\Admin\Http\Requests\ManageRequest;
class ManageController extends Controller
{
    //显示列表
    public function index()
    {

        $data = Manage::paginate(10);

        return view('admin::manage.index', compact('data'));
    }

    //创建视图
    public function create(Manage $manage)
    {
       //取出所有客服组数据
        $chatgroups = Chatgroup::all();
        //取出所有角色数据
        $roles = Role::all();

        return view('admin::manage.create',compact('manage','chatgroups','roles'));
    }

    //保存数据
    public function store(ManageRequest $request,Manage $manage)
    {
        $manage->insertUser($request->all());
        return redirect('/admin/manage')->with('success', '保存成功');
    }

    //显示记录
    public function show(Manage $field)
    {
        return view('admin::manage.show', compact('field'));
    }

    //编辑视图
    public function edit(Manage $manage)
    {
        //取出所有客服组数据
        $chatgroups = Chatgroup::all();
        //取出所有角色数据
        $roles = Role::all();

        return view('admin::manage.edit', compact('manage','chatgroups','roles'));
    }

    //更新数据
    public function update(ManageRequest $request, Manage $manage)
    {
//        dd($request->all());
        $manage->updateUser($request->all());
        return redirect('/admin/manage')->with('success','更新成功');
    }

    //删除模型
    public function destroy(Manage $manage)
    {
        $manage->delete();
        return redirect('admin/manage')->with('success','删除成功');
    }
}
